package edu.haiu.training.data1.content;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class ContentBean {
	private static final String username1 ="root";
	private static final String password1 ="123456";
	private static final String database1 ="jdbc:mysql://localhost:3306/mydb";
	List<Content> contents = new ArrayList<Content>();
	public List<Content> getContents() {
		return contents;
	}
	public void setContents(List<Content> contents) {
		this.contents = contents;
	}
	public String execute() throws Exception{
		
		Connection connection = DriverManager.getConnection(database1,username1,password1);
		String qs= "select * from mydb.content";
		PreparedStatement st= connection.prepareStatement(qs);
		ResultSet rs = st.executeQuery(qs);
		
		while(rs.next()){
			Content content = new Content();
			content.setId_content(rs.getInt("id_content"));
			content.setName_content(rs.getString("content_name"));
			content.setDate_update(String.valueOf(new java.sql.Date(rs.getDate("date_update").getTime())));
			content.setDetail_content(rs.getString("detail_content"));
			contents.add(content);
		}
		
		return "success";
	}
}
